<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class HotSearch extends Model
{
    protected $fillable = [
        'keyword',
        'search_count',
        'click_count',
        'last_searched_at',
    ];

    protected $casts = [
        'search_count' => 'integer',
        'click_count' => 'integer',
        'last_searched_at' => 'datetime',
    ];

    /**
     * 增加搜索次数
     */
    public function incrementSearchCount(): void
    {
        $this->increment('search_count');
        $this->update(['last_searched_at' => now()]);
    }

    /**
     * 增加点击次数
     */
    public function incrementClickCount(): void
    {
        $this->increment('click_count');
    }
}
